//
//  ChooseProSegVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/9/15.
//  Copyright © 2021 zwb. All rights reserved.
//

import UIKit
enum ZyaChooseProType:String {
    case classification,search,collection,tree
}

class ZyaChooseProSegVC: DQBaseHomeViewController {
    var s_customer_branch_id = ""
    var s_date = ""
    var s_orgid = ""
    var clientid = ""
//    var selectIDS = [String]()
    var productClosure:(([ZyaFOGoodTModel])->())?
    fileprivate let vc1: ChooseProClassVC = {
        let v = ChooseProClassVC()
        v.title = "分类"
        return v
    }()
    fileprivate let vctree: ChooseProTreeVC = {
        let v = ChooseProTreeVC()
        v.title = "类型"
        return v
    }()
    fileprivate let vc2: ChooseProSearchVC = {
        let v = ChooseProSearchVC()
        v.title = "搜索"
        return v
    }()
    fileprivate let vc3: ChooseProMarkVC = {
        let v = ChooseProMarkVC()
        v.title = "收藏"
        return v
    }()
    var typeX:ZyaChooseProType = .classification
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "选择产品"
        self.DQColer = Theme.primaryColor()
        vc1.s_orgid = s_orgid
        vc1.clientid = clientid
        vc1.s_customer_branch_id = s_customer_branch_id
        vc1.s_date = s_date
        
        vctree.s_orgid = s_orgid
        vctree.clientid = clientid
        vctree.s_customer_branch_id = s_customer_branch_id
        vctree.s_date = s_date
        
         vc2.s_orgid = s_orgid
        vc2.clientid = clientid
        vc2.s_customer_branch_id = s_customer_branch_id
        vc2.s_date = s_date
        
         vc3.s_orgid = s_orgid
        vc3.clientid = clientid
        vc3.s_customer_branch_id = s_customer_branch_id
        vc3.s_date = s_date
  
       
           self.addChild(vctree)
           self.addChild(vc2)
           self.addChild(vc3)
     
        
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "添加", style: .done, target: self, action: #selector(add))
        
    }
    
    @objc func add() {
        switch self.typeX {
        case .classification:
            if let clo = self.productClosure {
                let arr = vc1.itemArray.compactMap{ $0.goods }.flatMap{$0}.filter { $0.selectX }
                clo(arr)
            }
        case .tree:
            if let clo = self.productClosure {
                let arr = vctree.itemArray.filter { $0.selectX }
                clo(arr)
            }
        case .search:
            if let clo = self.productClosure {
                let arr =  vc2.markSearchArray.filter{ $0.selectX }
                clo(arr)
            }
        case .collection:
            if let clo = self.productClosure {
                let arr =  vc3.markSearchArray.filter{ $0.selectX }
                clo(arr)
            }
             
        default:
            break
        }
        self.navigationController?.popViewController(animated: true)
    }
    
    override func selectedTitle(title: String) {
        switch title {
        case "分类":
            self.typeX = .classification
        case "类型":
            self.typeX = .tree
        case "搜索":
            self.typeX = .search
        case "收藏":
            self.typeX = .collection
        default:
            break
        }
    }
    
    
    
    
}
